Skip to content

Conversation

Nkovaturient
Copy link
Contributor

fix: content routing provider data handling and test cases

Description

Fixed the content routing implementation to ensure proper handling of provider data and JSON content types. All test cases are now passing across different environments (Node.js, Browser, WebWorker).

Key improvements:

  • Added proper Content-Type: application/json headers
  • Fixed provider data JSON formatting
  • Added routing initialization in tests
  • Fixed multiaddrs format handling in assertions

Test Results:

  • Node.js: 23 passing, 2 pending
  • Browser: 25 passing
  • WebWorker: 23 passing, 2 pending

Note: The 2 pending tests are related to cache TTL functionality, which is expected behavior.

Notes & open questions

None - all test cases are passing as expected across environments.

Change checklist

  • [✅] I have performed a self-review of my own code
  • [✅] I have made corresponding changes to the documentation (updated test cases with proper JSON formatting)
  • [✅] I have added tests that prove my fix is effective

@achingbrain
Copy link
Member

achingbrain commented Feb 3, 2025

Thanks for opening this. Please can you run ‘npm run lint -- --fix’ to reformat your changes according to the existing linting rules.

@Nkovaturient
Copy link
Contributor Author

@achingbrain sure

@Nkovaturient
Copy link
Contributor Author

@achingbrain Done✅

@achingbrain
Copy link
Member

packages/client/.aegir.js has gained semicolons, trailing commas, and had it's ' characters swapped for ".

Several files have many whitespace changes also.

Please revert these changes, they just add noise to the PR and make it harder to review.

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are multiple edits to code that doesn't seem like anything has changed other than style/lint fixes from a tool other than eslint/aegir and our eslint-config-ipfs rules.

those should definitely be addressed so we can determine what actual code changes were made.

Comment on lines 64 to 83
const providers = [
{
Protocol: 'transport-bitswap',
Schema: 'bitswap',
Metadata: 'gBI=',
ID: (await generateKeyPair('Ed25519')).publicKey.toString(),
Addrs: ['/ip4/41.41.41.41/tcp/1234']
},
{
Protocol: 'transport-bitswap',
Schema: 'peer',
Metadata: 'gBI=',
ID: (await generateKeyPair('Ed25519')).publicKey.toString(),
Addrs: ['/ip4/42.42.42.42/tcp/1234']
},
{
ID: (await generateKeyPair('Ed25519')).publicKey.toString(),
Addrs: ['/ip4/43.43.43.43/tcp/1234']
}
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this change is style only, and unnecessary.

I would highly recommend disabling editorconfig and auto styling that is not using eslint or aegir. If you disable auto-save, you should be able to run npm run lint -- --fix to fix issues until you get your editor to a good place.

FYI: my editor is vscode, and I have https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint installed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alryt thanks for the guidance. Will do it as desired

@SgtPooki SgtPooki changed the title Perf & Enhancement: Content Routing fix: getProviders recognizes application/json accept header Feb 4, 2025
@Nkovaturient
Copy link
Contributor Author

thanks @SgtPooki @achingbrain for the review and advice---
I have modified so far as advised.

  • [✅ ] Disabled Auto-save, auto-formatting
  • [✅ ] vscode/settings.json as per IPFS eslint implementation

kindly look into it and provide guidance.
Thank you for your time.

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review because it still seems like a lot of stylistic and unnecessary changes were made

@@ -1,96 +1,200 @@
import EchoServer from 'aegir/echo-server'
import body from 'body-parser'
import EchoServer from "aegir/echo-server";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to remove stylistic changes here and in the rest of the PR.

You might need to git checkout main -- <pathToFile> and then discard everything except the changes that are needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay! lemme try it out👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file still has a lot of single quotes changed to double quote, and semicolons added...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i cannot understand, despite disabling autosave, eslint, why extra spaces, semicolons and double quotes are added. can you please guide me how to configure my vs-setup--I have downloaded this vsc extension--https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint--and then ran npm run lint -- --fix, even did git checkout main --, and tried minimal code changes, yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, from the root of the project, because this is a monorepo, you actually have to run npm run lint -- -- --fix

next();
lastCalledUrl = req.url;
});
// echo.polka.post("/add-providers/:cid", (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah!

Comment on lines 24 to 29
client = createDelegatedRoutingV1HttpApiClient(new URL(serverUrl), { cacheTTL: 0 })
client = createDelegatedRoutingV1HttpApiClient(new URL(serverUrl), {
cacheTTL: 0
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary edit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is irrelevant, my apology

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one still needs addressed

Comment on lines 53 to 67
await fetch(`${process.env.ECHO_SERVER}/add-providers/${cid.toString()}`, {
method: 'POST',
body: providers.map(prov => JSON.stringify(prov)).join('\n')
})
await fetch(
`${process.env.ECHO_SERVER}/add-providers/${cid.toString()}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ Providers: providers })
}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary formatting change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the test case was returning err when headers wasnt added here!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but there are still formatting changes here that aren't necessary. e.g. we should still have await fetch(${process.env.ECHO_SERVER}/add-providers/${cid.toString()}, { on the initial line here AFAIK.

@Nkovaturient
Copy link
Contributor Author

packages/client/.aegir.js has gained semicolons, trailing commas, and had it's ' characters swapped for ".

Several files have many whitespace changes also.

Please revert these changes, they just add noise to the PR and make it harder to review.

@achingbrain @SgtPooki
I humbly apologise for my unstructured code changes. It wont happen again. Thank you again for guiding.

@Nkovaturient
Copy link
Contributor Author

@SgtPooki

  • I ran git checkout --main,
  • compared and subscribed to optimal code changes
  • ipfs/helia eslint practices
  • minimal reformatting and
  • worked afresh in carrying out the changes in Content-type header.

Kindly review it.

@@ -1,96 +1,200 @@
import EchoServer from 'aegir/echo-server'
import body from 'body-parser'
import EchoServer from "aegir/echo-server";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file still has a lot of single quotes changed to double quote, and semicolons added...

Comment on lines 11 to 14
import {
createDelegatedRoutingV1HttpApiClient,
type DelegatedRoutingV1HttpApiClient
} from '../src/index.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another unnecessary change

Suggested change
import {
createDelegatedRoutingV1HttpApiClient,
type DelegatedRoutingV1HttpApiClient
} from '../src/index.js'
import { createDelegatedRoutingV1HttpApiClient, type DelegatedRoutingV1HttpApiClient } from '../src/index.js'

Comment on lines 24 to 29
client = createDelegatedRoutingV1HttpApiClient(new URL(serverUrl), { cacheTTL: 0 })
client = createDelegatedRoutingV1HttpApiClient(new URL(serverUrl), {
cacheTTL: 0
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one still needs addressed

@Nkovaturient
Copy link
Contributor Author

@SgtPooki
made desired changes,
is it upto the mark?🙂

@Nkovaturient
Copy link
Contributor Author

Kindly guide further?

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the code a bit.. lgtm now.

@SgtPooki SgtPooki requested a review from achingbrain February 10, 2025 21:45
@SgtPooki SgtPooki merged commit 8fd603b into ipfs:main Feb 11, 2025
19 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 11, 2025
## [@helia/delegated-routing-v1-http-api-client-v4.2.2](https://github.com/ipfs/helia-delegated-routing-v1-http-api/compare/@helia/delegated-routing-v1-http-api-client-4.2.1...@helia/delegated-routing-v1-http-api-client-4.2.2) (2025-02-11)

### Bug Fixes

* getProviders recognizes application/json accept header ([#155](#155)) ([8fd603b](8fd603b))
Copy link

🎉 This PR is included in version @helia/delegated-routing-v1-http-api-client-v4.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getProviders returns empty array if delegated routing server returns Content-Type header that is not "application/json" exactly
3 participants